import {METHOD} from './config'
import axios from 'axios'
const instance = axios.create({
  // baseURL: 'http://adminv2.happymmall.com/manage',
  // timeout: 1000,
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  transformRequest: [function (data) {
    let ret = ''
    for (let it in data) {
      ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
    }
    return ret
  }]
})
export function request(method, url, params) {
  switch (method) {
    case METHOD.GET:
      return get(url, params)
    case METHOD.POST:
      return post(url, params)
  }
}

function get(url, params) {
  return instance.get(url, params)
}

function post(url, params) {
  return instance.post(url, params)
}
